//
//  JrdChangePasswordViewController.m
//  iMandarin
//
//  Created by longcheng on 16/7/23.
//  Copyright © 2016年 Singro. All rights reserved.
//

#import "JrdChangePhoneViewController.h"
#import "JrdCommon.h"
#import "JrdDatamanager.h"
#define JRD_SEC_VIEW (185)
#define JRD_TEXT_HEIGHT (50)
#define JRD_HEAD_HEIGHT    (15)
#define JRD_SPE_HEIGHT  (10)
@interface JrdChangePhoneViewController ()
@property (nonatomic, strong) SCBarButtonItem *leftBarItem;
@property (nonatomic, strong) SCBarButtonItem *rightBarItem;
@end

@implementation JrdChangePhoneViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self configureNavibarItems];

    self.sc_navigationItem.leftBarButtonItem = self.leftBarItem;
    self.sc_navigationItem.rightBarButtonItem = self.rightBarItem;
    self.view.backgroundColor = JrdTableHeadColor;
    
    [self initView];

}
- (void)viewDidAppear:(BOOL)animated{
    self.sc_navigationItem.title = NSLocalizedString(@"jrd_change_Phone",nil);//@"我们学习";
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

- (void)configureNavibarItems {
    self.leftBarItem = [[SCBarButtonItem alloc] initWithTitle:NSLocalizedString(@"jrd_cancel", nil) style:SCBarButtonItemStylePlain handler:^(id sender) {
        [self.navigationController popViewControllerAnimated:YES];
    }];
    
    self.rightBarItem = [[SCBarButtonItem alloc] initWithTitle:NSLocalizedString(@"jrd_done", nil) style:SCBarButtonItemStylePlain handler:^(id sender) {
        [JrdDatamanager manager].user.phoneNumber = self.old_PhoneNumber.text;
        [[JrdDatamanager manager] setUserPhone:self.old_PhoneNumber.text];
        [self.navigationController popViewControllerAnimated:YES];
        [[NSNotificationCenter defaultCenter] postNotificationName:kReloadUserNotification object:self];

    }];
    
}

- (void)delOldPassword{
    self.old_PhoneNumber.text=@"";
}

- (void)initView{
    UIView* view = [[UIView alloc] initWithFrame:CGRectMake(0,  (STATUS_BAR_HEIGHT+NAVIGATION_BAR_HEIGHT), SCREEN_WIDTH, JRD_SEC_VIEW)];
    view.backgroundColor = JrdTableHeadColor;
    [self.view addSubview:view];
    UIView* view_v_p = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 15, JRD_TEXT_HEIGHT)];
    UIView* del_view = [[UIView alloc] initWithFrame:CGRectMake(0,  (JRD_TEXT_HEIGHT - 20)/2, 30, 20)];
    UIButton* delView = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
    [delView setBackgroundImage:[UIImage imageNamed:@"ico_delete"] forState:UIControlStateNormal];
    [delView addTarget:self action:@selector(delOldPassword) forControlEvents:UIControlEventTouchUpInside];
    [del_view addSubview:delView];

    UIView* view_ = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 15, JRD_TEXT_HEIGHT)];
        self.old_PhoneNumber = [[UITextField alloc] initWithFrame:CGRectMake(0, JRD_HEAD_HEIGHT, SCREEN_WIDTH, JRD_TEXT_HEIGHT)];
    //self.old_PhoneNumber.secureTextEntry = YES;
    self.old_PhoneNumber.text  = [JrdDatamanager manager].user.phoneNumber;// @"123456";
    self.old_PhoneNumber.enabled = true;
    self.old_PhoneNumber.backgroundColor = JrdWhite1Color;
    self.old_PhoneNumber.leftView = view_;
    self.old_PhoneNumber.leftViewMode = UITextFieldViewModeAlways;
    self.old_PhoneNumber.rightViewMode = UITextFieldViewModeAlways;
    self.old_PhoneNumber.rightView=del_view;
    [view addSubview: self.old_PhoneNumber];
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
